<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Linux 网络管理 | 知识库</title>
    <meta name="generator" content="VuePress 1.9.2">
    <link rel="icon" href="/vuepress-theme-vdoing-doc/img/favicon.ico">
    <noscript><meta http-equiv="refresh" content="0; url=https://www.youngkbt.cn/noscript/"><style>.theme-vdoing-content { display:none }</noscript>
    <meta name="description" content="一个基于VuePress的 知识管理">
    <meta name="keywords" content="vuepress,theme,blog,vdoing">
    <meta name="theme-color" content="#11a8cd">
    
    <link rel="preload" href="/vuepress-theme-vdoing-doc/assets/css/0.styles.b0974950.css" as="style"><link rel="preload" href="/vuepress-theme-vdoing-doc/assets/js/app.f061d58b.js" as="script"><link rel="preload" href="/vuepress-theme-vdoing-doc/assets/js/2.9bf30e88.js" as="script"><link rel="preload" href="/vuepress-theme-vdoing-doc/assets/js/73.002db3b4.js" as="script"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/10.d2937c56.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/11.67567365.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/12.74e8c324.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/13.2376fcd7.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/14.57ef5c33.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/15.44e7c0ba.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/16.c2fb4c44.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/17.af212389.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/18.1e6acac7.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/19.54653ac9.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/20.920cc499.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/21.37128fe3.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/22.8f68a2f2.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/23.7b9f1ba6.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/24.12adc291.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/25.cfe381e5.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/26.9cf879f6.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/27.4e6190ea.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/28.1e22fc79.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/29.c57e047d.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/3.cdcce428.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/30.21a95474.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/31.ce97e6e3.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/32.cdb45d73.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/33.fd95e780.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/34.cd49a408.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/35.fe128161.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/36.02043ece.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/37.02eee249.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/38.4650dec6.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/39.04fb7652.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/4.c02b1e5f.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/40.7b51f807.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/41.1df513a9.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/42.92a82cec.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/43.363fceef.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/44.867b24fd.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/45.89f64bfa.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/46.3a4c53d8.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/47.b8a31c80.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/48.7a584b38.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/49.98345029.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/5.cb45b2c7.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/50.6a0b68f4.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/51.8945cdf6.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/52.6583e327.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/53.f6987dfc.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/54.cca012f3.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/55.8c58cf5c.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/56.23e08364.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/57.08b54de0.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/58.131ee23e.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/59.45637607.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/6.c97c5dc9.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/60.fe9c5dd1.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/61.39ad8fda.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/62.ede47d34.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/63.4bb3e179.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/64.23f955bc.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/65.77ffc240.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/66.a4503c94.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/67.bd3d6fa6.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/68.a003ac59.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/69.64c66f41.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/7.1e88af32.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/70.87dfbf7d.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/71.02806218.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/72.54e30335.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/74.e577570e.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/75.e610b3c9.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/76.f684a067.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/77.8be17062.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/78.cabc6873.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/79.83febd7c.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/8.91701106.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/80.19e3b7ca.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/81.1b4cafb3.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/82.752ef803.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/83.460cd49b.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/84.377a221f.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/85.016eaf98.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/86.604c5deb.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/87.d3a3662d.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/88.0cf7f581.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/89.40b002bd.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/9.94309dfb.js"><link rel="prefetch" href="/vuepress-theme-vdoing-doc/assets/js/90.086847f8.js">
    <link rel="stylesheet" href="/vuepress-theme-vdoing-doc/assets/css/0.styles.b0974950.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/vuepress-theme-vdoing-doc/" class="home-link router-link-active"><img src="/vuepress-theme-vdoing-doc/img/logo.png" alt="知识库" class="logo"> <span class="site-name can-hide">知识库</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/vuepress-theme-vdoing-doc/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="指南" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/a2f161/" class="link-title">指南</a> <span class="title" style="display:none;">指南</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/52d5c3/" class="nav-link">主题初衷与诞生</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/a2f161/" class="nav-link">介绍</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/e08c97/" class="nav-link">模板集</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="案例" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/5d571c/" class="link-title">案例</a> <span class="title" style="display:none;">案例</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/5d571c/" class="nav-link">01.后端.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/4bd4c3/" class="nav-link">02.前端.md</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Docker" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/68917f/" class="link-title">Docker</a> <span class="title" style="display:none;">Docker</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/68917f/" class="nav-link">Docker安装与卸载</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/ceaf16/" class="nav-link">Docker常用命令</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Linux" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/489582/" class="link-title">Linux</a> <span class="title" style="display:none;">Linux</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/489582/" class="nav-link">01.防火墙设置.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/6babae/" class="nav-link">02.Linux文件压缩和解压要点.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/ccdc52/" class="nav-link">03.Linux 文件目录管理.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/503b98/" class="nav-link">04.Linux 文件内容查看编辑.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/e7b850/" aria-current="page" class="nav-link router-link-exact-active router-link-active">05.Linux 网络管理.md</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="空间聚合" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/a3137a/" class="link-title">空间聚合</a> <span class="title" style="display:none;">空间聚合</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/a3137a/" class="nav-link">OGC标准函数</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="后端" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/fcb182/" class="link-title">后端</a> <span class="title" style="display:none;">后端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>MyBatis</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/vuepress-theme-vdoing-doc/pages/01e8a8/" class="nav-link">01.XML 映射器.md</a></li></ul></li><li class="dropdown-item"><h4>国产数据库</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/vuepress-theme-vdoing-doc/pages/3c4d09/" class="nav-link">01.达梦适配.md</a></li><li class="dropdown-subitem"><a href="/vuepress-theme-vdoing-doc/pages/3ab660/" class="nav-link">02.瀚高适配.md</a></li></ul></li><li class="dropdown-item"><h4>Selenium爬取数据</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/vuepress-theme-vdoing-doc/pages/e110c2/" class="nav-link">spring boot+selenium爬取数据.md</a></li></ul></li></ul></div></div> <a href="https://gitee.com/" target="_blank" rel="noopener noreferrer" class="repo-link">
    Source
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><!----> <nav class="nav-links"><div class="nav-item"><a href="/vuepress-theme-vdoing-doc/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="指南" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/a2f161/" class="link-title">指南</a> <span class="title" style="display:none;">指南</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/52d5c3/" class="nav-link">主题初衷与诞生</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/a2f161/" class="nav-link">介绍</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/e08c97/" class="nav-link">模板集</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="案例" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/5d571c/" class="link-title">案例</a> <span class="title" style="display:none;">案例</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/5d571c/" class="nav-link">01.后端.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/4bd4c3/" class="nav-link">02.前端.md</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Docker" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/68917f/" class="link-title">Docker</a> <span class="title" style="display:none;">Docker</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/68917f/" class="nav-link">Docker安装与卸载</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/ceaf16/" class="nav-link">Docker常用命令</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Linux" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/489582/" class="link-title">Linux</a> <span class="title" style="display:none;">Linux</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/489582/" class="nav-link">01.防火墙设置.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/6babae/" class="nav-link">02.Linux文件压缩和解压要点.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/ccdc52/" class="nav-link">03.Linux 文件目录管理.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/503b98/" class="nav-link">04.Linux 文件内容查看编辑.md</a></li><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/e7b850/" aria-current="page" class="nav-link router-link-exact-active router-link-active">05.Linux 网络管理.md</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="空间聚合" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/a3137a/" class="link-title">空间聚合</a> <span class="title" style="display:none;">空间聚合</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vuepress-theme-vdoing-doc/pages/a3137a/" class="nav-link">OGC标准函数</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="后端" class="dropdown-title"><a href="/vuepress-theme-vdoing-doc/pages/fcb182/" class="link-title">后端</a> <span class="title" style="display:none;">后端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>MyBatis</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/vuepress-theme-vdoing-doc/pages/01e8a8/" class="nav-link">01.XML 映射器.md</a></li></ul></li><li class="dropdown-item"><h4>国产数据库</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/vuepress-theme-vdoing-doc/pages/3c4d09/" class="nav-link">01.达梦适配.md</a></li><li class="dropdown-subitem"><a href="/vuepress-theme-vdoing-doc/pages/3ab660/" class="nav-link">02.瀚高适配.md</a></li></ul></li><li class="dropdown-item"><h4>Selenium爬取数据</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/vuepress-theme-vdoing-doc/pages/e110c2/" class="nav-link">spring boot+selenium爬取数据.md</a></li></ul></li></ul></div></div> <a href="https://gitee.com/" target="_blank" rel="noopener noreferrer" class="repo-link">
    Source
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav> <div class="sidebar-slot sidebar-slot-top">
  <a href="http://apifox.cn/a103xugaoyi" target="_blank">
<!--    <img src="https://cdn.staticaly.com/gh/xugaoyi/blog-gitalk-comment@master/img/431669861564_.2470ykdcpbds.jpg" alt="npm" class="no-zoom" style="width: 100%;border-radius: 2px;">-->
<!--    <p style="text-align: center;margin: 0;color: #999;font-size: 12px;">(进入注册为作者充电)</p>-->
  </a></div> <ul class="sidebar-links"><li><a href="/vuepress-theme-vdoing-doc/pages/489582/" class="sidebar-link">防火墙设置</a></li><li><a href="/vuepress-theme-vdoing-doc/pages/6babae/" class="sidebar-link">Linux文件压缩和解压要点</a></li><li><a href="/vuepress-theme-vdoing-doc/pages/ccdc52/" class="sidebar-link">Linux 文件目录管理</a></li><li><a href="/vuepress-theme-vdoing-doc/pages/503b98/" class="sidebar-link">Linux 文件内容查看编辑</a></li><li><a href="/vuepress-theme-vdoing-doc/pages/e7b850/" aria-current="page" class="active sidebar-link">Linux 网络管理</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_1-linux-网络应用要点" class="sidebar-link">1. Linux 网络应用要点</a></li><li class="sidebar-sub-header level2"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-命令常见用法" class="sidebar-link">2. 命令常见用法</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-1-curl" class="sidebar-link">2.1. curl</a></li><li class="sidebar-sub-header level3"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-2-wget" class="sidebar-link">2.2. wget</a></li><li class="sidebar-sub-header level3"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-3-telnet" class="sidebar-link">2.3. telnet</a></li><li class="sidebar-sub-header level3"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-4-ip" class="sidebar-link">2.4. ip</a></li><li class="sidebar-sub-header level3"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-5-hostname" class="sidebar-link">2.5. hostname</a></li><li class="sidebar-sub-header level3"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-6-ifconfig" class="sidebar-link">2.6. ifconfig</a></li><li class="sidebar-sub-header level3"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-7-route" class="sidebar-link">2.7. route</a></li><li class="sidebar-sub-header level3"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-8-ssh" class="sidebar-link">2.8. ssh</a></li><li class="sidebar-sub-header level3"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-9-ssh-keygen" class="sidebar-link">2.9. ssh-keygen</a></li><li class="sidebar-sub-header level3"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-10-firewalld" class="sidebar-link">2.10. firewalld</a></li><li class="sidebar-sub-header level4"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-10-1-firewalld-的基本使用" class="sidebar-link">2.10.1. firewalld 的基本使用</a></li><li class="sidebar-sub-header level4"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-10-2-使用-systemctl-管理-firewalld-服务" class="sidebar-link">2.10.2. 使用 systemctl 管理 firewalld 服务</a></li><li class="sidebar-sub-header level4"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-10-3-配置-firewalld-cmd" class="sidebar-link">2.10.3. 配置 firewalld-cmd</a></li><li class="sidebar-sub-header level4"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-10-4-在防火墙中开放一个端口" class="sidebar-link">2.10.4. 在防火墙中开放一个端口</a></li><li class="sidebar-sub-header level3"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-11-iptables" class="sidebar-link">2.11. iptables</a></li><li class="sidebar-sub-header level3"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-12-host" class="sidebar-link">2.12. host</a></li><li class="sidebar-sub-header level3"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-13-nslookup" class="sidebar-link">2.13. nslookup</a></li><li class="sidebar-sub-header level3"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-14-nc-netcat" class="sidebar-link">2.14. nc/netcat</a></li><li class="sidebar-sub-header level3"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-15-ping" class="sidebar-link">2.15. ping</a></li><li class="sidebar-sub-header level3"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-16-traceroute" class="sidebar-link">2.16. traceroute</a></li><li class="sidebar-sub-header level3"><a href="/vuepress-theme-vdoing-doc/pages/e7b850/#_2-17-netstat" class="sidebar-link">2.17. netstat</a></li></ul></li></ul></li><li><a href="/vuepress-theme-vdoing-doc/pages/c7033b/" class="sidebar-link">系统磁盘扩容</a></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/vuepress-theme-vdoing-doc/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><span data-v-06225672>linux</span></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="https://gitee.com/wenlongjia" target="_blank" title="作者" class="beLink" data-v-06225672>Insist</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>2023-05-25</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">Linux 网络管理<!----></h1> <div class="page-slot page-slot-top">
    <div class="wwads-cn wwads-horizontal page-wwads" data-id="136"></div>
    <style>
      .page-wwads{
        width:100%!important;
        min-height: 0;
        margin: 0;
      }
      .page-wwads .wwads-img img{
        width:80px!important;
      }
      .page-wwads .wwads-poweredby{
        width: 40px;
        position: absolute;
        right: 25px;
        bottom: 3px;
      }
      .wwads-content .wwads-text, .page-wwads .wwads-text{
        height: 100%;
        padding-top: 5px;
        display: block;
      }
  </style>
  </div> <div class="theme-vdoing-content content__default"><h1 id="linux-网络管理"><a href="#linux-网络管理" class="header-anchor">#</a> Linux 网络管理</h1> <blockquote><p>关键词：<code>curl</code>, <code>wget</code>, <code>telnet</code>, <code>ip</code>, <code>hostname</code>, <code>ifconfig</code>, <code>route</code>, <code>ssh</code>, <code>ssh-keygen</code>, <code>firewalld</code>, <code>iptables</code>, <code>host</code>, <code>nslookup</code>, <code>nc</code>/<code>netcat</code>, <code>ping</code>, <code>traceroute</code>, <code>netstat</code></p></blockquote> <h2 id="_1-linux-网络应用要点"><a href="#_1-linux-网络应用要点" class="header-anchor">#</a> 1. Linux 网络应用要点</h2> <ul><li>下载文件 - 使用 <a href="#curl">curl</a>、<a href="#wget">wget</a></li> <li>telnet 方式登录远程主机，对远程主机进行管理 - 使用 <a href="#telnet">telnet</a></li> <li>查看或操纵 Linux 主机的路由、网络设备、策略路由和隧道 - 使用 <a href="#ip">ip</a></li> <li>查看和设置系统的主机名 - 使用 <a href="#hostname">hostname</a></li> <li>查看和配置 Linux 内核中网络接口的网络参数 - 使用 <a href="#ifconfig">ifconfig</a></li> <li>查看和设置 Linux 内核中的网络路由表 - 使用 <a href="#route">route</a></li> <li>ssh 方式连接远程主机 - 使用 ssh</li> <li>为 ssh 生成、管理和转换认证密钥 - 使用 <a href="#ssh-keygen">ssh-keygen</a></li> <li>查看、设置防火墙（Centos7），使用 <a href="#firewalld">firewalld</a></li> <li>查看、设置防火墙（Centos7 以前），使用 <a href="#iptables">iptables</a></li> <li>查看域名信息 - 使用 <a href="#host">host</a>, <a href="#nslookup">nslookup</a></li> <li>设置路由 - 使用 <a href="#ncnetcat">nc/netcat</a></li> <li>测试主机之间网络是否连通 - 使用 <a href="#ping">ping</a></li> <li>追踪数据在网络上的传输时的全部路径 - 使用 <a href="#traceroute">traceroute</a></li> <li>查看当前工作的端口信息 - 使用 <a href="#netstat">netstat</a></li></ul> <h2 id="_2-命令常见用法"><a href="#_2-命令常见用法" class="header-anchor">#</a> 2. 命令常见用法</h2> <h3 id="_2-1-curl"><a href="#_2-1-curl" class="header-anchor">#</a> 2.1. curl</h3> <blockquote><p>curl 命令是一个利用 URL 规则在命令行下工作的文件传输工具。它支持文件的上传和下载，所以是综合传输工具，但按传统，习惯称 curl 为下载工具。作为一款强力工具，curl 支持包括 HTTP、HTTPS、ftp 等众多协议，还支持 POST、cookies、认证、从指定偏移处下载部分文件、用户代理字符串、限速、文件大小、进度条等特征。做网页处理流程和数据检索自动化，curl 可以祝一臂之力。</p></blockquote> <p>示例：</p> <h3 id="_2-2-wget"><a href="#_2-2-wget" class="header-anchor">#</a> 2.2. wget</h3> <blockquote><p>wget 命令用来从指定的 URL 下载文件。</p></blockquote> <p>示例：</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 使用 wget 下载单个文件</span>
$ <span class="token function">wget</span> http://www.linuxde.net/testfile.zip
</code></pre></div><h3 id="_2-3-telnet"><a href="#_2-3-telnet" class="header-anchor">#</a> 2.3. telnet</h3> <blockquote><p>telnet 命令用于登录远程主机，对远程主机进行管理。</p></blockquote> <p>示例：</p> <div class="language-bash extra-class"><pre class="language-bash"><code>telnet <span class="token number">192.168</span>.2.10
Trying <span class="token number">192.168</span>.2.10<span class="token punctuation">..</span>.
Connected to <span class="token number">192.168</span>.2.10 <span class="token punctuation">(</span><span class="token number">192.168</span>.2.10<span class="token punctuation">)</span>.
Escape character is <span class="token string">'^]'</span><span class="token builtin class-name">.</span>

    localhost <span class="token punctuation">(</span>Linux release <span class="token number">2.6</span>.18-274.18.1.el5 <span class="token comment">#1 SMP Thu Feb 9 12:45:44 EST 2012) (1)</span>

login: root
Password:
Login incorrect
</code></pre></div><h3 id="_2-4-ip"><a href="#_2-4-ip" class="header-anchor">#</a> 2.4. ip</h3> <blockquote><p>ip 命令用来查看或操纵 Linux 主机的路由、网络设备、策略路由和隧道，是 Linux 下较新的功能强大的网络配置工具。</p></blockquote> <p>示例：</p> <div class="language-bash extra-class"><pre class="language-bash"><code>$ <span class="token function">ip</span> <span class="token function">link</span> show                     <span class="token comment"># 查看网络接口信息</span>
$ <span class="token function">ip</span> <span class="token function">link</span> <span class="token builtin class-name">set</span> eth0 upi             <span class="token comment"># 开启网卡</span>
$ <span class="token function">ip</span> <span class="token function">link</span> <span class="token builtin class-name">set</span> eth0 down            <span class="token comment"># 关闭网卡</span>
$ <span class="token function">ip</span> <span class="token function">link</span> <span class="token builtin class-name">set</span> eth0 promisc on      <span class="token comment"># 开启网卡的混合模式</span>
$ <span class="token function">ip</span> <span class="token function">link</span> <span class="token builtin class-name">set</span> eth0 promisc offi    <span class="token comment"># 关闭网卡的混个模式</span>
$ <span class="token function">ip</span> <span class="token function">link</span> <span class="token builtin class-name">set</span> eth0 txqueuelen <span class="token number">1200</span> <span class="token comment"># 设置网卡队列长度</span>
$ <span class="token function">ip</span> <span class="token function">link</span> <span class="token builtin class-name">set</span> eth0 mtu <span class="token number">1400</span>        <span class="token comment"># 设置网卡最大传输单元</span>
$ <span class="token function">ip</span> addr show     <span class="token comment"># 查看网卡IP信息</span>
$ <span class="token function">ip</span> addr <span class="token function">add</span> <span class="token number">192.168</span>.0.1/24 dev eth0 <span class="token comment"># 设置eth0网卡IP地址192.168.0.1</span>
$ <span class="token function">ip</span> addr del <span class="token number">192.168</span>.0.1/24 dev eth0 <span class="token comment"># 删除eth0网卡IP地址</span>

$ <span class="token function">ip</span> route show <span class="token comment"># 查看系统路由</span>
$ <span class="token function">ip</span> route <span class="token function">add</span> default via <span class="token number">192.168</span>.1.254   <span class="token comment"># 设置系统默认路由</span>
$ <span class="token function">ip</span> route list                 <span class="token comment"># 查看路由信息</span>
$ <span class="token function">ip</span> route <span class="token function">add</span> <span class="token number">192.168</span>.4.0/24  via  <span class="token number">192.168</span>.0.254 dev eth0 <span class="token comment"># 设置192.168.4.0网段的网关为192.168.0.254,数据走eth0接口</span>
$ <span class="token function">ip</span> route <span class="token function">add</span> default via  <span class="token number">192.168</span>.0.254  dev eth0        <span class="token comment"># 设置默认网关为192.168.0.254</span>
$ <span class="token function">ip</span> route del <span class="token number">192.168</span>.4.0/24   <span class="token comment"># 删除192.168.4.0网段的网关</span>
$ <span class="token function">ip</span> route del default          <span class="token comment"># 删除默认路由</span>
$ <span class="token function">ip</span> route delete <span class="token number">192.168</span>.1.0/24 dev eth0 <span class="token comment"># 删除路由</span>
</code></pre></div><h3 id="_2-5-hostname"><a href="#_2-5-hostname" class="header-anchor">#</a> 2.5. hostname</h3> <blockquote><p>hostname 命令用于查看和设置系统的主机名称。环境变量 HOSTNAME 也保存了当前的主机名。在使用 hostname 命令设置主机名后，系统并不会永久保存新的主机名，重新启动机器之后还是原来的主机名。如果需要永久修改主机名，需要同时修改 <code>/etc/hosts</code> 和 <code>/etc/sysconfig/network</code> 的相关内容。</p></blockquote> <p>示例：</p> <div class="language-bash extra-class"><pre class="language-bash"><code>$ <span class="token function">hostname</span>
AY1307311912260196fcZ
</code></pre></div><h3 id="_2-6-ifconfig"><a href="#_2-6-ifconfig" class="header-anchor">#</a> 2.6. ifconfig</h3> <blockquote><p>ifconfig 命令被用于查看和配置 Linux 内核中网络接口的网络参数。用 ifconfig 命令配置的网卡信息，在网卡重启后机器重启后，配置就不存在。要想将上述的配置信息永远的存的电脑里，那就要修改网卡的配置文件了。</p></blockquote> <p>示例：</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 查看网络设备信息（激活状态的）</span>
<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span><span class="token comment"># ifconfig</span>
eth0      Link encap:Ethernet  HWaddr 00:16:3E:00:1E:51
          inet addr:10.160.7.81  Bcast:10.160.15.255  Mask:255.255.240.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:61430830 errors:0 dropped:0 overruns:0 frame:0
          TX packets:88534 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3607197869 <span class="token punctuation">(</span><span class="token number">3.3</span> GiB<span class="token punctuation">)</span>  TX bytes:6115042 <span class="token punctuation">(</span><span class="token number">5.8</span> MiB<span class="token punctuation">)</span>

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:56103 errors:0 dropped:0 overruns:0 frame:0
          TX packets:56103 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:5079451 <span class="token punctuation">(</span><span class="token number">4.8</span> MiB<span class="token punctuation">)</span>  TX bytes:5079451 <span class="token punctuation">(</span><span class="token number">4.8</span> MiB<span class="token punctuation">)</span>
</code></pre></div><h3 id="_2-7-route"><a href="#_2-7-route" class="header-anchor">#</a> 2.7. route</h3> <blockquote><p>route 命令用来查看和设置 Linux 内核中的网络路由表，route 命令设置的路由主要是静态路由。要实现两个不同的子网之间的通信，需要一台连接两个网络的路由器，或者同时位于两个网络的网关来实现。</p></blockquote> <p>示例：</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 查看当前路由</span>
route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
<span class="token number">112.124</span>.12.0    *               <span class="token number">255.255</span>.252.0   U     <span class="token number">0</span>      <span class="token number">0</span>        <span class="token number">0</span> eth1
<span class="token number">10.160</span>.0.0      *               <span class="token number">255.255</span>.240.0   U     <span class="token number">0</span>      <span class="token number">0</span>        <span class="token number">0</span> eth0
<span class="token number">192.168</span>.0.0     <span class="token number">10.160</span>.15.247   <span class="token number">255.255</span>.0.0     UG    <span class="token number">0</span>      <span class="token number">0</span>        <span class="token number">0</span> eth0
<span class="token number">172.16</span>.0.0      <span class="token number">10.160</span>.15.247   <span class="token number">255.240</span>.0.0     UG    <span class="token number">0</span>      <span class="token number">0</span>        <span class="token number">0</span> eth0
<span class="token number">10.0</span>.0.0        <span class="token number">10.160</span>.15.247   <span class="token number">255.0</span>.0.0       UG    <span class="token number">0</span>      <span class="token number">0</span>        <span class="token number">0</span> eth0
default         <span class="token number">112.124</span>.15.247  <span class="token number">0.0</span>.0.0         UG    <span class="token number">0</span>      <span class="token number">0</span>        <span class="token number">0</span> eth1

route <span class="token function">add</span> <span class="token parameter variable">-net</span> <span class="token number">224.0</span>.0.0 netmask <span class="token number">240.0</span>.0.0 dev eth0    <span class="token comment"># 添加网关/设置网关</span>
route <span class="token function">add</span> <span class="token parameter variable">-net</span> <span class="token number">224.0</span>.0.0 netmask <span class="token number">240.0</span>.0.0 reject      <span class="token comment"># 屏蔽一条路由</span>
route del <span class="token parameter variable">-net</span> <span class="token number">224.0</span>.0.0 netmask <span class="token number">240.0</span>.0.0             <span class="token comment"># 删除路由记录</span>
route <span class="token function">add</span> default gw <span class="token number">192.168</span>.120.240                   <span class="token comment"># 添加默认网关</span>
route del default gw <span class="token number">192.168</span>.120.240                   <span class="token comment"># 删除默认网关</span>
</code></pre></div><h3 id="_2-8-ssh"><a href="#_2-8-ssh" class="header-anchor">#</a> 2.8. ssh</h3> <blockquote><p>ssh 命令是 openssh 套件中的客户端连接工具，可以给予 ssh 加密协议实现安全的远程登录服务器。</p></blockquote> <p>示例：</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># ssh 用户名@远程服务器地址</span>
<span class="token function">ssh</span> user1@172.24.210.101
<span class="token comment"># 指定端口</span>
<span class="token function">ssh</span> <span class="token parameter variable">-p</span> <span class="token number">2211</span> root@140.206.185.170
</code></pre></div><p>引申阅读：<a href="https://linux.cn/article-8476-1.html" target="_blank" rel="noopener noreferrer">ssh 背后的故事<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <h3 id="_2-9-ssh-keygen"><a href="#_2-9-ssh-keygen" class="header-anchor">#</a> 2.9. ssh-keygen</h3> <blockquote><p>ssh-keygen 命令用于为 ssh 生成、管理和转换认证密钥，它支持 RSA 和 DSA 两种认证密钥。</p></blockquote> <h3 id="_2-10-firewalld"><a href="#_2-10-firewalld" class="header-anchor">#</a> 2.10. firewalld</h3> <blockquote><p>firewalld 命令是 Linux 上的防火墙软件（Centos7 默认防火墙）。</p> <p>参考：https://www.cnblogs.com/moxiaoan/p/5683743.html</p></blockquote> <h4 id="_2-10-1-firewalld-的基本使用"><a href="#_2-10-1-firewalld-的基本使用" class="header-anchor">#</a> 2.10.1. firewalld 的基本使用</h4> <ul><li>启动 - systemctl start firewalld</li> <li>关闭 - systemctl stop firewalld</li> <li>查看状态 - systemctl status firewalld</li> <li>开机禁用 - systemctl disable firewalld</li> <li>开机启用 - systemctl enable firewalld</li></ul> <h4 id="_2-10-2-使用-systemctl-管理-firewalld-服务"><a href="#_2-10-2-使用-systemctl-管理-firewalld-服务" class="header-anchor">#</a> 2.10.2. 使用 systemctl 管理 firewalld 服务</h4> <p>systemctl 是 CentOS7 的服务管理工具中主要的工具，它融合之前 service 和 chkconfig 的功能于一体。</p> <ul><li>启动一个服务 - systemctl start firewalld.service</li> <li>关闭一个服务 - systemctl stop firewalld.service</li> <li>重启一个服务 - systemctl restart firewalld.service</li> <li>显示一个服务的状态 - systemctl status firewalld.service</li> <li>在开机时启用一个服务 - systemctl enable firewalld.service</li> <li>在开机时禁用一个服务 - systemctl disable firewalld.service</li> <li>查看服务是否开机启动 - systemctl is-enabled firewalld.service</li> <li>查看已启动的服务列表 - systemctl list-unit-files|grep enabled</li> <li>查看启动失败的服务列表 - systemctl --failed</li></ul> <h4 id="_2-10-3-配置-firewalld-cmd"><a href="#_2-10-3-配置-firewalld-cmd" class="header-anchor">#</a> 2.10.3. 配置 firewalld-cmd</h4> <ul><li>查看版本 - firewall-cmd --version</li> <li>查看帮助 - firewall-cmd --help</li> <li>显示状态 - firewall-cmd --state</li> <li>查看所有打开的端口 - firewall-cmd --zone=public --list-ports</li> <li>更新防火墙规则 - firewall-cmd --reload</li> <li>查看区域信息: firewall-cmd --get-active-zones</li> <li>查看指定接口所属区域 - firewall-cmd --get-zone-of-interface=eth0</li> <li>拒绝所有包：firewall-cmd --panic-on</li> <li>取消拒绝状态 - firewall-cmd --panic-off</li> <li>查看是否拒绝 - firewall-cmd --query-panic</li></ul> <h4 id="_2-10-4-在防火墙中开放一个端口"><a href="#_2-10-4-在防火墙中开放一个端口" class="header-anchor">#</a> 2.10.4. 在防火墙中开放一个端口</h4> <ul><li>添加（--permanent 永久生效，没有此参数重启后失效） - firewall-cmd --zone=public --add-port=80/tcp --permanent</li> <li>重新载入 - firewall-cmd --reload</li> <li>查看 - firewall-cmd --zone= public --query-port=80/tcp</li> <li>删除 - firewall-cmd --zone= public --remove-port=80/tcp --permanent</li></ul> <h3 id="_2-11-iptables"><a href="#_2-11-iptables" class="header-anchor">#</a> 2.11. iptables</h3> <blockquote><p>iptables 命令是 Linux 上常用的防火墙软件，是 netfilter 项目的一部分。可以直接配置，也可以通过许多前端和图形界面配置。</p></blockquote> <p>示例：</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 开放指定的端口</span>
iptables <span class="token parameter variable">-A</span> INPUT <span class="token parameter variable">-s</span> <span class="token number">127.0</span>.0.1 <span class="token parameter variable">-d</span> <span class="token number">127.0</span>.0.1 <span class="token parameter variable">-j</span> ACCEPT               <span class="token comment">#允许本地回环接口(即运行本机访问本机)</span>
iptables <span class="token parameter variable">-A</span> INPUT <span class="token parameter variable">-m</span> state <span class="token parameter variable">--state</span> ESTABLISHED,RELATED <span class="token parameter variable">-j</span> ACCEPT    <span class="token comment">#允许已建立的或相关连的通行</span>
iptables <span class="token parameter variable">-A</span> OUTPUT <span class="token parameter variable">-j</span> ACCEPT         <span class="token comment">#允许所有本机向外的访问</span>
iptables <span class="token parameter variable">-A</span> INPUT <span class="token parameter variable">-p</span> tcp <span class="token parameter variable">--dport</span> <span class="token number">22</span> <span class="token parameter variable">-j</span> ACCEPT    <span class="token comment">#允许访问22端口</span>
iptables <span class="token parameter variable">-A</span> INPUT <span class="token parameter variable">-p</span> tcp <span class="token parameter variable">--dport</span> <span class="token number">80</span> <span class="token parameter variable">-j</span> ACCEPT    <span class="token comment">#允许访问80端口</span>
iptables <span class="token parameter variable">-A</span> INPUT <span class="token parameter variable">-p</span> tcp <span class="token parameter variable">--dport</span> <span class="token number">21</span> <span class="token parameter variable">-j</span> ACCEPT    <span class="token comment">#允许ftp服务的21端口</span>
iptables <span class="token parameter variable">-A</span> INPUT <span class="token parameter variable">-p</span> tcp <span class="token parameter variable">--dport</span> <span class="token number">20</span> <span class="token parameter variable">-j</span> ACCEPT    <span class="token comment">#允许FTP服务的20端口</span>
iptables <span class="token parameter variable">-A</span> INPUT <span class="token parameter variable">-j</span> reject       <span class="token comment">#禁止其他未允许的规则访问</span>
iptables <span class="token parameter variable">-A</span> FORWARD <span class="token parameter variable">-j</span> REJECT     <span class="token comment">#禁止其他未允许的规则访问</span>

<span class="token comment"># 屏蔽IP</span>
iptables <span class="token parameter variable">-I</span> INPUT <span class="token parameter variable">-s</span> <span class="token number">123.45</span>.6.7 <span class="token parameter variable">-j</span> DROP       <span class="token comment">#屏蔽单个IP的命令</span>
iptables <span class="token parameter variable">-I</span> INPUT <span class="token parameter variable">-s</span> <span class="token number">123.0</span>.0.0/8 <span class="token parameter variable">-j</span> DROP      <span class="token comment">#封整个段即从123.0.0.1到123.255.255.254的命令</span>
iptables <span class="token parameter variable">-I</span> INPUT <span class="token parameter variable">-s</span> <span class="token number">124.45</span>.0.0/16 <span class="token parameter variable">-j</span> DROP    <span class="token comment">#封IP段即从123.45.0.1到123.45.255.254的命令</span>
iptables <span class="token parameter variable">-I</span> INPUT <span class="token parameter variable">-s</span> <span class="token number">123.45</span>.6.0/24 <span class="token parameter variable">-j</span> DROP    <span class="token comment">#封IP段即从123.45.6.1到123.45.6.254的命令是</span>

<span class="token comment"># 查看已添加的iptables规则</span>
iptables <span class="token parameter variable">-L</span> <span class="token parameter variable">-n</span> <span class="token parameter variable">-v</span>
Chain INPUT <span class="token punctuation">(</span>policy DROP <span class="token number">48106</span> packets, 2690K bytes<span class="token punctuation">)</span>
 pkts bytes target     prot opt <span class="token keyword">in</span>     out     <span class="token builtin class-name">source</span>               destination
 <span class="token number">5075</span>  589K ACCEPT     all  --  lo     *       <span class="token number">0.0</span>.0.0/0            <span class="token number">0.0</span>.0.0/0
 191K   90M ACCEPT     tcp  --  *      *       <span class="token number">0.0</span>.0.0/0            <span class="token number">0.0</span>.0.0/0           tcp dpt:22
1499K  133M ACCEPT     tcp  --  *      *       <span class="token number">0.0</span>.0.0/0            <span class="token number">0.0</span>.0.0/0           tcp dpt:80
4364K 6351M ACCEPT     all  --  *      *       <span class="token number">0.0</span>.0.0/0            <span class="token number">0.0</span>.0.0/0           state RELATED,ESTABLISHED
 <span class="token number">6256</span>  327K ACCEPT     icmp --  *      *       <span class="token number">0.0</span>.0.0/0            <span class="token number">0.0</span>.0.0/0

Chain FORWARD <span class="token punctuation">(</span>policy ACCEPT <span class="token number">0</span> packets, <span class="token number">0</span> bytes<span class="token punctuation">)</span>
 pkts bytes target     prot opt <span class="token keyword">in</span>     out     <span class="token builtin class-name">source</span>               destination

Chain OUTPUT <span class="token punctuation">(</span>policy ACCEPT 3382K packets, 1819M bytes<span class="token punctuation">)</span>
 pkts bytes target     prot opt <span class="token keyword">in</span>     out     <span class="token builtin class-name">source</span>               destination
 <span class="token number">5075</span>  589K ACCEPT     all  --  *      lo      <span class="token number">0.0</span>.0.0/0            <span class="token number">0.0</span>.0.0/0
</code></pre></div><h3 id="_2-12-host"><a href="#_2-12-host" class="header-anchor">#</a> 2.12. host</h3> <blockquote><p>host 命令是常用的分析域名查询工具，可以用来测试域名系统工作是否正常。</p></blockquote> <p>示例：</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span><span class="token comment"># host www.jsdig.com</span>
www.jsdig.com is an <span class="token builtin class-name">alias</span> <span class="token keyword">for</span> host.1.jsdig.com.
host.1.jsdig.com has address <span class="token number">100.42</span>.212.8

<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span><span class="token comment"># host -a www.jsdig.com</span>
Trying <span class="token string">&quot;www.jsdig.com&quot;</span>
<span class="token punctuation">;</span><span class="token punctuation">;</span> -<span class="token operator">&gt;&gt;</span>HEADER<span class="token operator">&lt;&lt;-</span> opcode: QUERY, status: NOERROR, id: <span class="token number">34671</span>
<span class="token punctuation">;</span><span class="token punctuation">;</span> flags: qr rd ra<span class="token punctuation">;</span> QUERY: <span class="token number">1</span>, ANSWER: <span class="token number">1</span>, AUTHORITY: <span class="token number">0</span>, ADDITIONAL: <span class="token number">0</span>

<span class="token punctuation">;</span><span class="token punctuation">;</span> QUESTION SECTION:
<span class="token punctuation">;</span>www.jsdig.com.               IN      ANY

<span class="token punctuation">;</span><span class="token punctuation">;</span> ANSWER SECTION:
www.jsdig.com.        <span class="token number">463</span>     IN      CNAME   host.1.jsdig.com.

Received <span class="token number">54</span> bytes from <span class="token number">202.96</span>.104.15<span class="token comment">#53 in 0 ms</span>
</code></pre></div><h3 id="_2-13-nslookup"><a href="#_2-13-nslookup" class="header-anchor">#</a> 2.13. nslookup</h3> <blockquote><p>nslookup 命令是常用域名查询工具，就是查 DNS 信息用的命令。</p></blockquote> <p>示例：</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span><span class="token comment"># nslookup www.jsdig.com</span>
Server:         <span class="token number">202.96</span>.104.15
Address:        <span class="token number">202.96</span>.104.15<span class="token comment">#53</span>

Non-authoritative answer:
www.jsdig.com canonical name <span class="token operator">=</span> host.1.jsdig.com.
Name:   host.1.jsdig.com
Address: <span class="token number">100.42</span>.212.8
</code></pre></div><h3 id="_2-14-nc-netcat"><a href="#_2-14-nc-netcat" class="header-anchor">#</a> 2.14. nc/netcat</h3> <blockquote><p>nc 命令是 netcat 命令的简称，都是用来设置路由器。</p></blockquote> <p>示例：</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># TCP 端口扫描</span>
<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span><span class="token comment"># nc -v -z -w2 192.168.0.3 1-100</span>
<span class="token number">192.168</span>.0.3: inverse <span class="token function">host</span> lookup failed: Unknown <span class="token function">host</span>
<span class="token punctuation">(</span>UNKNOWN<span class="token punctuation">)</span> <span class="token punctuation">[</span><span class="token number">192.168</span>.0.3<span class="token punctuation">]</span> <span class="token number">80</span> <span class="token punctuation">(</span>http<span class="token punctuation">)</span> <span class="token function">open</span>
<span class="token punctuation">(</span>UNKNOWN<span class="token punctuation">)</span> <span class="token punctuation">[</span><span class="token number">192.168</span>.0.3<span class="token punctuation">]</span> <span class="token number">23</span> <span class="token punctuation">(</span>telnet<span class="token punctuation">)</span> <span class="token function">open</span>
<span class="token punctuation">(</span>UNKNOWN<span class="token punctuation">)</span> <span class="token punctuation">[</span><span class="token number">192.168</span>.0.3<span class="token punctuation">]</span> <span class="token number">22</span> <span class="token punctuation">(</span>ssh<span class="token punctuation">)</span> <span class="token function">open</span>

<span class="token comment"># UDP 端口扫描</span>
<span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span><span class="token comment"># nc -u -z -w2 192.168.0.1 1-1000  # 扫描192.168.0.3 的端口 范围是 1-1000</span>
</code></pre></div><h3 id="_2-15-ping"><a href="#_2-15-ping" class="header-anchor">#</a> 2.15. ping</h3> <blockquote><p>ping 命令用来测试主机之间网络的连通性。执行 ping 指令会使用 ICMP 传输协议，发出要求回应的信息，若远端主机的网络功能没有问题，就会回应该信息，因而得知该主机运作正常。</p></blockquote> <p>示例：</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token punctuation">[</span>root@AY1307311912260196fcZ ~<span class="token punctuation">]</span><span class="token comment"># ping www.jsdig.com</span>
PING host.1.jsdig.com <span class="token punctuation">(</span><span class="token number">100.42</span>.212.8<span class="token punctuation">)</span> <span class="token number">56</span><span class="token punctuation">(</span><span class="token number">84</span><span class="token punctuation">)</span> bytes of data.
<span class="token number">64</span> bytes from <span class="token number">100</span>-42-212-8.static.webnx.com <span class="token punctuation">(</span><span class="token number">100.42</span>.212.8<span class="token punctuation">)</span>: <span class="token assign-left variable">icmp_seq</span><span class="token operator">=</span><span class="token number">1</span> <span class="token assign-left variable">ttl</span><span class="token operator">=</span><span class="token number">50</span> <span class="token assign-left variable">time</span><span class="token operator">=</span><span class="token number">177</span> ms
<span class="token number">64</span> bytes from <span class="token number">100</span>-42-212-8.static.webnx.com <span class="token punctuation">(</span><span class="token number">100.42</span>.212.8<span class="token punctuation">)</span>: <span class="token assign-left variable">icmp_seq</span><span class="token operator">=</span><span class="token number">2</span> <span class="token assign-left variable">ttl</span><span class="token operator">=</span><span class="token number">50</span> <span class="token assign-left variable">time</span><span class="token operator">=</span><span class="token number">178</span> ms
<span class="token number">64</span> bytes from <span class="token number">100</span>-42-212-8.static.webnx.com <span class="token punctuation">(</span><span class="token number">100.42</span>.212.8<span class="token punctuation">)</span>: <span class="token assign-left variable">icmp_seq</span><span class="token operator">=</span><span class="token number">3</span> <span class="token assign-left variable">ttl</span><span class="token operator">=</span><span class="token number">50</span> <span class="token assign-left variable">time</span><span class="token operator">=</span><span class="token number">174</span> ms
<span class="token number">64</span> bytes from <span class="token number">100</span>-42-212-8.static.webnx.com <span class="token punctuation">(</span><span class="token number">100.42</span>.212.8<span class="token punctuation">)</span>: <span class="token assign-left variable">icmp_seq</span><span class="token operator">=</span><span class="token number">4</span> <span class="token assign-left variable">ttl</span><span class="token operator">=</span><span class="token number">50</span> <span class="token assign-left variable">time</span><span class="token operator">=</span><span class="token number">177</span> ms
<span class="token punctuation">..</span>.按Ctrl+C结束

--- host.1.jsdig.com <span class="token function">ping</span> statistics ---
<span class="token number">4</span> packets transmitted, <span class="token number">4</span> received, <span class="token number">0</span>% packet loss, <span class="token function">time</span> 2998ms
rtt min/avg/max/mdev <span class="token operator">=</span> <span class="token number">174.068</span>/176.916/178.182/1.683 ms
</code></pre></div><h3 id="_2-16-traceroute"><a href="#_2-16-traceroute" class="header-anchor">#</a> 2.16. traceroute</h3> <blockquote><p>traceroute 命令用于追踪数据包在网络上的传输时的全部路径，它默认发送的数据包大小是 40 字节。</p></blockquote> <p>示例：</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">traceroute</span> www.58.com
<span class="token function">traceroute</span> to www.58.com <span class="token punctuation">(</span><span class="token number">211.151</span>.111.30<span class="token punctuation">)</span>, <span class="token number">30</span> hops max, <span class="token number">40</span> byte packets
 <span class="token number">1</span>  unknown <span class="token punctuation">(</span><span class="token number">192.168</span>.2.1<span class="token punctuation">)</span>  <span class="token number">3.453</span> ms  <span class="token number">3.801</span> ms  <span class="token number">3.937</span> ms
 <span class="token number">2</span>  <span class="token number">221.6</span>.45.33 <span class="token punctuation">(</span><span class="token number">221.6</span>.45.33<span class="token punctuation">)</span>  <span class="token number">7.768</span> ms  <span class="token number">7.816</span> ms  <span class="token number">7.840</span> ms
 <span class="token number">3</span>  <span class="token number">221.6</span>.0.233 <span class="token punctuation">(</span><span class="token number">221.6</span>.0.233<span class="token punctuation">)</span>  <span class="token number">13.784</span> ms  <span class="token number">13.827</span> ms <span class="token number">221.6</span>.9.81 <span class="token punctuation">(</span><span class="token number">221.6</span>.9.81<span class="token punctuation">)</span>  <span class="token number">9.758</span> ms
 <span class="token number">4</span>  <span class="token number">221.6</span>.2.169 <span class="token punctuation">(</span><span class="token number">221.6</span>.2.169<span class="token punctuation">)</span>  <span class="token number">11.777</span> ms <span class="token number">122.96</span>.66.13 <span class="token punctuation">(</span><span class="token number">122.96</span>.66.13<span class="token punctuation">)</span>  <span class="token number">34.952</span> ms <span class="token number">221.6</span>.2.53 <span class="token punctuation">(</span><span class="token number">221.6</span>.2.53<span class="token punctuation">)</span>  <span class="token number">41.372</span> ms
 <span class="token number">5</span>  <span class="token number">219.158</span>.96.149 <span class="token punctuation">(</span><span class="token number">219.158</span>.96.149<span class="token punctuation">)</span>  <span class="token number">39.167</span> ms  <span class="token number">39.210</span> ms  <span class="token number">39.238</span> ms
 <span class="token number">6</span>  <span class="token number">123.126</span>.0.194 <span class="token punctuation">(</span><span class="token number">123.126</span>.0.194<span class="token punctuation">)</span>  <span class="token number">37.270</span> ms <span class="token number">123.126</span>.0.66 <span class="token punctuation">(</span><span class="token number">123.126</span>.0.66<span class="token punctuation">)</span>  <span class="token number">37.163</span> ms  <span class="token number">37.441</span> ms
 <span class="token number">7</span>  <span class="token number">124.65</span>.57.26 <span class="token punctuation">(</span><span class="token number">124.65</span>.57.26<span class="token punctuation">)</span>  <span class="token number">42.787</span> ms  <span class="token number">42.799</span> ms  <span class="token number">42.809</span> ms
 <span class="token number">8</span>  <span class="token number">61.148</span>.146.210 <span class="token punctuation">(</span><span class="token number">61.148</span>.146.210<span class="token punctuation">)</span>  <span class="token number">30.176</span> ms <span class="token number">61.148</span>.154.98 <span class="token punctuation">(</span><span class="token number">61.148</span>.154.98<span class="token punctuation">)</span>  <span class="token number">32.613</span> ms  <span class="token number">32.675</span> ms
 <span class="token number">9</span>  <span class="token number">202.106</span>.42.102 <span class="token punctuation">(</span><span class="token number">202.106</span>.42.102<span class="token punctuation">)</span>  <span class="token number">44.563</span> ms  <span class="token number">44.600</span> ms  <span class="token number">44.627</span> ms
<span class="token number">10</span>  <span class="token number">210.77</span>.139.150 <span class="token punctuation">(</span><span class="token number">210.77</span>.139.150<span class="token punctuation">)</span>  <span class="token number">53.302</span> ms  <span class="token number">53.233</span> ms  <span class="token number">53.032</span> ms
<span class="token number">11</span>  <span class="token number">211.151</span>.104.6 <span class="token punctuation">(</span><span class="token number">211.151</span>.104.6<span class="token punctuation">)</span>  <span class="token number">39.585</span> ms  <span class="token number">39.502</span> ms  <span class="token number">39.598</span> ms
<span class="token number">12</span>  <span class="token number">211.151</span>.111.30 <span class="token punctuation">(</span><span class="token number">211.151</span>.111.30<span class="token punctuation">)</span>  <span class="token number">35.161</span> ms  <span class="token number">35.938</span> ms  <span class="token number">36.005</span> ms
</code></pre></div><h3 id="_2-17-netstat"><a href="#_2-17-netstat" class="header-anchor">#</a> 2.17. netstat</h3> <blockquote><p>netstat 命令用来打印 Linux 中网络系统的状态信息，可让你得知整个 Linux 系统的网络情况。</p></blockquote> <p>示例：</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 列出所有端口 (包括监听和未监听的)</span>
<span class="token function">netstat</span> <span class="token parameter variable">-a</span>     <span class="token comment">#列出所有端口</span>
<span class="token function">netstat</span> <span class="token parameter variable">-at</span>    <span class="token comment">#列出所有tcp端口</span>
<span class="token function">netstat</span> <span class="token parameter variable">-au</span>    <span class="token comment">#列出所有udp端口</span>

<span class="token comment"># 列出所有处于监听状态的 Sockets</span>
<span class="token function">netstat</span> <span class="token parameter variable">-l</span>        <span class="token comment">#只显示监听端口</span>
<span class="token function">netstat</span> <span class="token parameter variable">-lt</span>       <span class="token comment">#只列出所有监听 tcp 端口</span>
<span class="token function">netstat</span> <span class="token parameter variable">-lu</span>       <span class="token comment">#只列出所有监听 udp 端口</span>
<span class="token function">netstat</span> <span class="token parameter variable">-lx</span>       <span class="token comment">#只列出所有监听 UNIX 端口</span>

<span class="token comment"># 显示每个协议的统计信息</span>
<span class="token function">netstat</span> <span class="token parameter variable">-s</span>   显示所有端口的统计信息
<span class="token function">netstat</span> <span class="token parameter variable">-st</span>   显示TCP端口的统计信息
<span class="token function">netstat</span> <span class="token parameter variable">-su</span>   显示UDP端口的统计信息
</code></pre></div></div></div>  <div class="page-edit"><!----> <!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2023/08/14, 13:28:01</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/vuepress-theme-vdoing-doc/pages/503b98/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">Linux 文件内容查看编辑</div></a> <a href="/vuepress-theme-vdoing-doc/pages/c7033b/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">系统磁盘扩容</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/vuepress-theme-vdoing-doc/pages/503b98/" class="prev">Linux 文件内容查看编辑</a></span> <span class="next"><a href="/vuepress-theme-vdoing-doc/pages/c7033b/">系统磁盘扩容</a>→
      </span></p></div></div></div> <!----></main></div> <div class="footer"><div class="icons"></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2023-2024
    <span>Insist | MIT License</span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"></div></div>
    <script src="/vuepress-theme-vdoing-doc/assets/js/app.f061d58b.js" defer></script><script src="/vuepress-theme-vdoing-doc/assets/js/2.9bf30e88.js" defer></script><script src="/vuepress-theme-vdoing-doc/assets/js/73.002db3b4.js" defer></script>
  </body>
</html>
